import { getInterfaceList } from '@/api/test/index';
import { CodeTableStatus, stopwatchColor } from '@/enums/statusEnum';
import { returnInterfaceType, interfaceType } from '@/pages/CodeTables/specification';
const tableData: interfaceType = reactive({
  apiName: '',
  apiSource: '',
  apiStatus: '',
  directoryCode: '',
  pageNum: 1,
  pageSize: 20,
  total: 10,
});
const data = ref<[]>([]);
const loading = ref<boolean>(false);
// 查询list
const getList = async () => {
  loading.value = true;
  try {
    const res = await getInterfaceList(tableData);
    res.records.forEach((item: returnInterfaceType) => {
      item.updateTime = new Date(item.updateTime).toLocaleString();
      // 向后端请求数据对象中添加了statusColor用于控制状态颜色
      item.statusColor = stopwatchColor[+item.apiStatus];
      item.apiStatus = CodeTableStatus[+item.apiStatus];
    });
    data.value = res.records as [];
    tableData.total = res.total;
    loading.value = false;
    console.log(res);
  } catch (error) {
    loading.value = false;
  }
};

export function getInterfaceManagementHook() {
  return {
    getList,
    tableData,
    data,
    loading,
  };
}
